<template>
    <view>
        <uni-list>
            <uni-list-item v-for="(item, index) in serviceStaff" :key="index" @click="() => selectItem(item)" :clickable="true" :title="item.orName" rightText="点击选择"> </uni-list-item>
            <u-empty v-if="serviceStaff.length === 0" text="暂无数据"> </u-empty>
        </uni-list>
    </view>
</template>

<script>
import { getStaffAll, updateCurrentServiceItem } from "../../utils/api";
import { mapGetters } from "vuex";

export default {
    data() {
        return {
            serviceStaff: [],
            serviceRecord: {},
            customerRankFissionAmount: [], // 裂变订单总额
            crUuid: "",
            siUuid: "",
            requestStatus: false,
        };
    },

    async onLoad(params) {
        this.crUuid = params.crUuid;
        this.siUuid = params.siUuid;
        this.ciUuid = params.ciUuid;
        let res = await getStaffAll();
        if (res) {
            this.serviceStaff = res || [];
        }
    },

    computed: {
        ...mapGetters({
            staffInfo: "personInfo/staffInfo",
        }),
    },

    methods: {
        async selectItem(item) {
            if (this.requestStatus) return false;
            this.requestStatus = true;
            let saveData = {
                crUuid: this.crUuid,
                siUuid: this.siUuid,
                cdSsid: item.orUuid,
                cdSsna: item.orName,
                cdSsph: item.orPhon,
            };
            let res = await updateCurrentServiceItem(saveData);

            if (res) {
                let pages = getCurrentPages();
                let beforePage = pages[pages.length - 2];
                let ciUuid = this.ciUuid;
                uni.navigateBack({
                    success: function () {
                        beforePage.onLoad({ ciUuid });
                    },
                });
            }
            setTimeout(() => {
                this.requestStatus = false;
            });
        },
    },
};
</script>

<style lang="scss" scoped></style>
